<?php

namespace Member\Controller;

/**
 * ProductBrandController 控制器
 * @since 1.0 <2016-8-23> SoChishun <14507247@qq.com> Added.
 */
class ProductBrand extends AppbaseController {

    function indexSearch() {
        $search = I('param.');
        $where = array();
        if (!empty($search['word'])) {
            $where['title|code'] = array('like', '%' . $search['word'] . '%');
        }
        // $where['site_id'] = $this->site_id;
        return array('search' => $search, 'where' => $where);
    }

    /**
     * 导出数据
     * @since 1.0 <2014-6-13> SoChishun Added.
     */
    public function export() {
        $asearch = $this->indexSearch();
        $mBrand = new \XWAM\Model\ProductBrandModel();
        $list = $mBrand->scope('export')->where($asearch['where'])->select();
        if (!$list) {
            $this->ajaxMsg(false, '找不到符合条件的记录!');
        }
        sofn_excel_export($list);
    }

    public function copy($id = 0) {
        if (!$id) {
            $this->ajaxMsg(false, '参数无效');
        }
        $mBrand = new \XWAM\Model\ProductBrandModel();
        $mBrand->copyBrand($id);
        $this->ajaxMsg(true);
    }

    public function index() {
        $asearch = $this->indexSearch();
        $mBrand = new \XWAM\Model\ProductBrandModel();
        $this->assign('tree', $mBrand->selectTree(array('where' => $asearch['where'])));
        $this->assign('search', $asearch['search']);
        $this->display();
    }

    public function edit($id = 0, $pid = 0) {
        $data = array();
        if ($id) {
            $mBrand = new \XWAM\Model\ProductBrandModel();
            $data = $mBrand->find($id);
        }
        $this->assign('data', $data);
        $this->display();
    }

    public function editSave() {
        $mBrand = new \XWAM\Model\ProductBrandModel();
        $result = $mBrand->saveBrand();
        $this->dialogJump($result['status'], $result['info']);
    }

    public function getListJson() {
        $mBrand = new \XWAM\Model\ProductBrandModel();
        $data=$mBrand->getIdTextList($this->siteId);
        $this->ajaxReturn($data);
    }

    public function getTreeJson($pid = 0) {
        $options = array();
        if ($pid) {
            $options['where']['pid'] = $pid;
        }
        $mBrand = new \XWAM\Model\ProductBrandModel();
        $data = $mBrand->selectTreeJson($options);
        $this->ajaxReturn($data);
    }

    function changeStatus($id, $status) {
        $mBrand = new \XWAM\Model\ProductBrandModel();
        $this->ajaxReturn($mBrand->changeStatus($id, $status));
    }

    function changeSort($id, $sort) {
        $mBrand = new \XWAM\Model\ProductBrandModel();
        $this->ajaxReturn($mBrand->changeSort($id, $sort));
    }

    /**
     * delete操作
     * @param string $id 主键编号
     * @since 1.0<2015-7-31> SoChishun Added.
     */
    public function delete($id = '') {
        $mBrand = new \XWAM\Model\ProductBrandModel();
        $this->ajaxReturn($mBrand->deleteBrand($id));
    }

}
